SlideShare a Scribd company logo
1 of 33
Class No.10  Data Structures http://ecomputernotes.com
Simulation of a Bank ,[object Object],[object Object],[object Object],[object Object],http://ecomputernotes.com
Simulation of a Bank ,[object Object],[object Object],[object Object],[object Object],http://ecomputernotes.com
Simulation of a Bank teller 2 teller 1 teller 3 teller 4 http://ecomputernotes.com
Simulation of a Bank teller 2 teller 1 teller 3 teller 4 http://ecomputernotes.com
Simulation of a Bank teller 2 teller 1 teller 3 teller 4 http://ecomputernotes.com
Simulation of a Bank teller 2 teller 1 teller 3 teller 4 http://ecomputernotes.com
Simulation of a Bank teller 2 teller 1 teller 3 teller 4 http://ecomputernotes.com
Simulation of a Bank teller 2 teller 1 teller 3 teller 4 http://ecomputernotes.com
Simulation of a Bank teller 2 teller 1 teller 3 teller 4 http://ecomputernotes.com
Simulation Models ,[object Object],[object Object],[object Object],http://ecomputernotes.com
Timeline based Simulation ,[object Object],[object Object],[object Object],[object Object],[object Object],http://ecomputernotes.com
Timeline based Simulation ,[object Object],1 0 11 10 8 7 6 5 4 3 2 15 14 13 12 C 2  in C 1  in C 1  out C 2  out C 3  in Time (minutes) http://ecomputernotes.com
Timeline based Simulation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],http://ecomputernotes.com
Event based Simulation ,[object Object],[object Object],[object Object],http://ecomputernotes.com
Event based Simulation ,[object Object],1 0 11 10 8 7 6 5 4 3 2 15 14 13 12 C 2  in C 1  in C 1  out C 2  out C 3  in Time (minutes) Event 1: 2 mins C1 in Event 2: 4 mins C2 in Event 3: 6 mins C1 out Event 4: 10 mins C2 out Event 5: 12 mins C3 in http://ecomputernotes.com
Event based Simulation ,[object Object],[object Object],[object Object],[object Object],http://ecomputernotes.com
Event based Bank Simulation ,[object Object],[object Object],[object Object],[object Object],[object Object],http://ecomputernotes.com
Arriving Customers’ File ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],http://ecomputernotes.com
Simulation Procedure  ,[object Object],[object Object],[object Object],[object Object],[object Object],http://ecomputernotes.com
Simulation Procedure ,[object Object],[object Object],[object Object],http://ecomputernotes.com
Simulation Procedure ,[object Object],[object Object],[object Object],[object Object],[object Object],http://ecomputernotes.com
Code for Simulation #include <iostream> #include <string> #include <strstream.h> #include &quot;Customer.cpp&quot; #include &quot;Queue.h&quot; #include &quot;PriorityQueue.cpp&quot; #include &quot;Event.cpp&quot; Queue q[4]; // teller queues PriorityQueue pq; //eventList; int totalTime; int count = 0; int customerNo = 0; http://ecomputernotes.com
Code for Simulation main (int argc, char *argv[])  { Customer* c; Event* nextEvent; // open customer arrival file ifstream data(&quot;customer.dat&quot;, ios::in); // initialize with the first arriving // customer. readNewCustomer(data); http://ecomputernotes.com
Code for Simulation while( pq.length() > 0 ) { nextEvent = pq.remove(); c = nextEvent->getCustomer(); if( c->getStatus() == -1 ){ // arrival event int arrTime = nextEvent->getEventTime(); int duration = c->getTransactionDuration(); int customerNo = c->getCustomerNumber(); processArrival(data, customerNo,  arrTime, duration , nextEvent); } else { // departure event int qindex = c->getStatus(); int departTime = nextEvent->getEventTime(); processDeparture(qindex, departTime, nextEvent); } } http://ecomputernotes.com
Code for Simulation void readNewCustomer(ifstream& data) { int hour,min,duration;  if (data >> hour >> min >> duration) { customerNo++; Customer* c = new Customer(customerNo,  hour*60+min, duration); c->setStatus( -1 ); // new arrival Event* e = new Event(c, hour*60+min ); pq.insert( e ); // insert the arrival event } else { data.close(); // close customer file } } http://ecomputernotes.com
Code for Simulation int processArrival(ifstream &data, int customerNo,  int arrTime, int duration,  Event* event) { int i, small, j = 0; // find smallest teller queue  small = q[0].length(); for(i=1; i < 4; i++ )  if( q[i].length() < small ){ small = q[i].length(); j = i; } // put arriving customer in smallest queue Customer* c = new Customer(customerNo, arrTime,  duration ); c->setStatus(j); // remember which queue the customer goes in q[j].enqueue(c); http://ecomputernotes.com
Code for Simulation // check if this is the only customer in the.  // queue. If so, the customer must be marked for  // departure by placing him on the event queue. if( q[j].length() == 1 ) { c->setDepartureTime( arrTime+duration); Event* e = new Event(c, arrTime+duration ); pq.insert(e); } // get another customer from the input readNewCustomer(data); } http://ecomputernotes.com
Code for Simulation int processDeparture( int qindex, int departTime,  Event* event) { Customer* cinq = q[qindex].dequeue(); int waitTime = departTime - cinq->getArrivalTime(); totalTime = totalTime + waitTime; count = count + 1; // if there are any more customers on the queue, mark the // next customer at the head of the queue for departure // and place him on the eventList. if( q[qindex].length() > 0 ) { cinq = q[qindex].front(); int etime = departTime + cinq->getTransactionDuration(); Event* e = new Event( cinq, etime); pq.insert( e ); }} http://ecomputernotes.com
Code for Simulation // print the final avaerage wait time. double avgWait = (totalTime*1.0)/count; cout << &quot;Total time: &quot; << totalTime << endl; cout << “Customer: &quot; << count << endl; cout << &quot;Average wait: &quot; << avgWait << endl; http://ecomputernotes.com
You may be thinking that the complete picture of simulation is not visible. How will we run this simulation? Another important tool in the simulation is animation. You have seen the animation of traffic. Cars are moving and stopping on the signals. Signals are turning into red, green and yellow. You can easily understand from the animation. If the animation is combined with the simulation, it is easily understood. We have an animated tool here that shows the animation of the events. A programmer can see the animation of the bank simulation. With the help of this animation, you can better understand the simulation.  http://ecomputernotes.com
In this animation, you can see the Entrance of the customers, four tellers, priority queue and the Exit. The customers enter the queue and as the tellers are free. They go to the teller straight. Customer C1<30, 10> enters the bank. The customer C1 enters after 30 mins and he needs 10 mins for the transaction. He goes to the teller 1. Then customer C2 enters the bank and goes to teller 2. When the transaction ends, the customer leaves the bank. When tellers are not free, customer will wait in the queue. In the event priority queue, we have different events. The entries in the priority queue are like  arr, 76  (arrival event at 76 min) or  q1, 80  (event in q1 at 80 min) etc. Let’s see the statistics when a customer leaves the bank. At exit, you see the customer leaving the bank as C15<68, 3><77, 3>, it means that the customer C15 enters the bank at 68 mins and requires 3 mins for his transaction. He goes to the teller 4 but the teller is not free, so the customer has to wait in the queue. He leaves the bank at 77 mins.
This course is not about the animation or simulation. We will solve the problems, using different data structures. Although with the help of simulation and animation, you can have a real sketch of the problem. http://ecomputernotes.com

More Related Content

Viewers also liked

e computer notes - Recursion
e computer notes - Recursione computer notes - Recursion
e computer notes - Recursion
ecomputernotes
 

Viewers also liked (17)

computer notes - Recursion
computer notes -  Recursioncomputer notes -  Recursion
computer notes - Recursion
 
e computer notes - Recursion
e computer notes - Recursione computer notes - Recursion
e computer notes - Recursion
 
Module 01 Stack and Recursion
Module 01 Stack and RecursionModule 01 Stack and Recursion
Module 01 Stack and Recursion
 
5 2
5 25 2
5 2
 
Computer notes - Analysis of Union
Computer notes  - Analysis of Union Computer notes  - Analysis of Union
Computer notes - Analysis of Union
 
The Stack And Recursion
The Stack And RecursionThe Stack And Recursion
The Stack And Recursion
 
Recursion
RecursionRecursion
Recursion
 
Recursion
RecursionRecursion
Recursion
 
Computer notes - Recursive
Computer notes  - RecursiveComputer notes  - Recursive
Computer notes - Recursive
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
C++ Memory Management
C++ Memory ManagementC++ Memory Management
C++ Memory Management
 
Recursion
RecursionRecursion
Recursion
 
8 memory management strategies
8 memory management strategies8 memory management strategies
8 memory management strategies
 
Memory management
Memory managementMemory management
Memory management
 
Memory management
Memory managementMemory management
Memory management
 
4. Recursion - Data Structures using C++ by Varsha Patil
4. Recursion - Data Structures using C++ by Varsha Patil4. Recursion - Data Structures using C++ by Varsha Patil
4. Recursion - Data Structures using C++ by Varsha Patil
 
Memory management
Memory managementMemory management
Memory management
 

Similar to computer notes - Data Structures - 10

Project 5Programming and Algorithms IICSCI 211, Spring 2.docx
Project 5Programming and Algorithms IICSCI 211, Spring 2.docxProject 5Programming and Algorithms IICSCI 211, Spring 2.docx
Project 5Programming and Algorithms IICSCI 211, Spring 2.docx
briancrawford30935
 
5-minute Practical Streaming Techniques that can Save You Millions
5-minute Practical Streaming Techniques that can Save You Millions5-minute Practical Streaming Techniques that can Save You Millions
5-minute Practical Streaming Techniques that can Save You Millions
HostedbyConfluent
 
#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx
AASTHA76
 
#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docx#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docx
mayank272369
 

Similar to computer notes - Data Structures - 10 (20)

Simulation for Bank Teller System
Simulation for Bank Teller SystemSimulation for Bank Teller System
Simulation for Bank Teller System
 
Project 5Programming and Algorithms IICSCI 211, Spring 2.docx
Project 5Programming and Algorithms IICSCI 211, Spring 2.docxProject 5Programming and Algorithms IICSCI 211, Spring 2.docx
Project 5Programming and Algorithms IICSCI 211, Spring 2.docx
 
5-minute Practical Streaming Techniques that can Save You Millions
5-minute Practical Streaming Techniques that can Save You Millions5-minute Practical Streaming Techniques that can Save You Millions
5-minute Practical Streaming Techniques that can Save You Millions
 
computer notes - Queues
computer notes - Queuescomputer notes - Queues
computer notes - Queues
 
DES
DES DES
DES
 
Atm Simulator
Atm SimulatorAtm Simulator
Atm Simulator
 
Atm Simulator
Atm SimulatorAtm Simulator
Atm Simulator
 
Operation research's CPM techniques
Operation research's CPM techniques Operation research's CPM techniques
Operation research's CPM techniques
 
WSO2 Complex Event Processor
WSO2 Complex Event ProcessorWSO2 Complex Event Processor
WSO2 Complex Event Processor
 
Proposed pricing model for cloud computing
Proposed pricing model for cloud computingProposed pricing model for cloud computing
Proposed pricing model for cloud computing
 
Presentation on vending machine controller using vhdl
Presentation on  vending machine controller  using vhdlPresentation on  vending machine controller  using vhdl
Presentation on vending machine controller using vhdl
 
#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx
 
#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docx#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docx
 
cbse 12 computer science investigatory project
cbse 12 computer science investigatory project  cbse 12 computer science investigatory project
cbse 12 computer science investigatory project
 
cbse 12 computer science investigatory project
cbse 12 computer science investigatory project  cbse 12 computer science investigatory project
cbse 12 computer science investigatory project
 
Critical path method
Critical path methodCritical path method
Critical path method
 
Jerry banks introduction to simulation
Jerry banks   introduction to simulationJerry banks   introduction to simulation
Jerry banks introduction to simulation
 
SIMUL8 Project
SIMUL8 ProjectSIMUL8 Project
SIMUL8 Project
 
Electricitybillsystemreport
ElectricitybillsystemreportElectricitybillsystemreport
Electricitybillsystemreport
 
Unleashing Real-World Simulations: A Python Tutorial by Avjinder Kaler
Unleashing Real-World Simulations: A Python Tutorial by Avjinder KalerUnleashing Real-World Simulations: A Python Tutorial by Avjinder Kaler
Unleashing Real-World Simulations: A Python Tutorial by Avjinder Kaler
 

More from ecomputernotes

computer notes - Data Structures - 39
computer notes - Data Structures - 39computer notes - Data Structures - 39
computer notes - Data Structures - 39
ecomputernotes
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11computer notes - Data Structures - 11
computer notes - Data Structures - 11
ecomputernotes
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20computer notes - Data Structures - 20
computer notes - Data Structures - 20
ecomputernotes
 
computer notes - Data Structures - 15
computer notes - Data Structures - 15computer notes - Data Structures - 15
computer notes - Data Structures - 15
ecomputernotes
 
Computer notes - Including Constraints
Computer notes - Including ConstraintsComputer notes - Including Constraints
Computer notes - Including Constraints
ecomputernotes
 
Computer notes - Date time Functions
Computer notes - Date time FunctionsComputer notes - Date time Functions
Computer notes - Date time Functions
ecomputernotes
 
Computer notes - Subqueries
Computer notes - SubqueriesComputer notes - Subqueries
Computer notes - Subqueries
ecomputernotes
 
Computer notes - Other Database Objects
Computer notes - Other Database ObjectsComputer notes - Other Database Objects
Computer notes - Other Database Objects
ecomputernotes
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28computer notes - Data Structures - 28
computer notes - Data Structures - 28
ecomputernotes
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19
ecomputernotes
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31computer notes - Data Structures - 31
computer notes - Data Structures - 31
ecomputernotes
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4
ecomputernotes
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13
ecomputernotes
 
Computer notes - Advanced Subqueries
Computer notes -   Advanced SubqueriesComputer notes -   Advanced Subqueries
Computer notes - Advanced Subqueries
ecomputernotes
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group FunctionsComputer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functions
ecomputernotes
 
computer notes - Data Structures - 16
computer notes - Data Structures - 16computer notes - Data Structures - 16
computer notes - Data Structures - 16
ecomputernotes
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22
ecomputernotes
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35computer notes - Data Structures - 35
computer notes - Data Structures - 35
ecomputernotes
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36computer notes - Data Structures - 36
computer notes - Data Structures - 36
ecomputernotes
 
Computer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY ClauseComputer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY Clause
ecomputernotes
 

More from ecomputernotes (20)

computer notes - Data Structures - 39
computer notes - Data Structures - 39computer notes - Data Structures - 39
computer notes - Data Structures - 39
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11computer notes - Data Structures - 11
computer notes - Data Structures - 11
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20computer notes - Data Structures - 20
computer notes - Data Structures - 20
 
computer notes - Data Structures - 15
computer notes - Data Structures - 15computer notes - Data Structures - 15
computer notes - Data Structures - 15
 
Computer notes - Including Constraints
Computer notes - Including ConstraintsComputer notes - Including Constraints
Computer notes - Including Constraints
 
Computer notes - Date time Functions
Computer notes - Date time FunctionsComputer notes - Date time Functions
Computer notes - Date time Functions
 
Computer notes - Subqueries
Computer notes - SubqueriesComputer notes - Subqueries
Computer notes - Subqueries
 
Computer notes - Other Database Objects
Computer notes - Other Database ObjectsComputer notes - Other Database Objects
Computer notes - Other Database Objects
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28computer notes - Data Structures - 28
computer notes - Data Structures - 28
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31computer notes - Data Structures - 31
computer notes - Data Structures - 31
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13
 
Computer notes - Advanced Subqueries
Computer notes -   Advanced SubqueriesComputer notes -   Advanced Subqueries
Computer notes - Advanced Subqueries
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group FunctionsComputer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functions
 
computer notes - Data Structures - 16
computer notes - Data Structures - 16computer notes - Data Structures - 16
computer notes - Data Structures - 16
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35computer notes - Data Structures - 35
computer notes - Data Structures - 35
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36computer notes - Data Structures - 36
computer notes - Data Structures - 36
 
Computer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY ClauseComputer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY Clause
 

Recently uploaded

CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
Wonjun Hwang
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
Microsoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfMicrosoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdf
Overkill Security
 

Recently uploaded (20)

2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Microsoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfMicrosoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdf
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 

computer notes - Data Structures - 10

  • 1. Class No.10 Data Structures http://ecomputernotes.com
  • 2.
  • 3.
  • 4. Simulation of a Bank teller 2 teller 1 teller 3 teller 4 http://ecomputernotes.com
  • 5. Simulation of a Bank teller 2 teller 1 teller 3 teller 4 http://ecomputernotes.com
  • 6. Simulation of a Bank teller 2 teller 1 teller 3 teller 4 http://ecomputernotes.com
  • 7. Simulation of a Bank teller 2 teller 1 teller 3 teller 4 http://ecomputernotes.com
  • 8. Simulation of a Bank teller 2 teller 1 teller 3 teller 4 http://ecomputernotes.com
  • 9. Simulation of a Bank teller 2 teller 1 teller 3 teller 4 http://ecomputernotes.com
  • 10. Simulation of a Bank teller 2 teller 1 teller 3 teller 4 http://ecomputernotes.com
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23. Code for Simulation #include <iostream> #include <string> #include <strstream.h> #include &quot;Customer.cpp&quot; #include &quot;Queue.h&quot; #include &quot;PriorityQueue.cpp&quot; #include &quot;Event.cpp&quot; Queue q[4]; // teller queues PriorityQueue pq; //eventList; int totalTime; int count = 0; int customerNo = 0; http://ecomputernotes.com
  • 24. Code for Simulation main (int argc, char *argv[]) { Customer* c; Event* nextEvent; // open customer arrival file ifstream data(&quot;customer.dat&quot;, ios::in); // initialize with the first arriving // customer. readNewCustomer(data); http://ecomputernotes.com
  • 25. Code for Simulation while( pq.length() > 0 ) { nextEvent = pq.remove(); c = nextEvent->getCustomer(); if( c->getStatus() == -1 ){ // arrival event int arrTime = nextEvent->getEventTime(); int duration = c->getTransactionDuration(); int customerNo = c->getCustomerNumber(); processArrival(data, customerNo, arrTime, duration , nextEvent); } else { // departure event int qindex = c->getStatus(); int departTime = nextEvent->getEventTime(); processDeparture(qindex, departTime, nextEvent); } } http://ecomputernotes.com
  • 26. Code for Simulation void readNewCustomer(ifstream& data) { int hour,min,duration; if (data >> hour >> min >> duration) { customerNo++; Customer* c = new Customer(customerNo, hour*60+min, duration); c->setStatus( -1 ); // new arrival Event* e = new Event(c, hour*60+min ); pq.insert( e ); // insert the arrival event } else { data.close(); // close customer file } } http://ecomputernotes.com
  • 27. Code for Simulation int processArrival(ifstream &data, int customerNo, int arrTime, int duration, Event* event) { int i, small, j = 0; // find smallest teller queue small = q[0].length(); for(i=1; i < 4; i++ ) if( q[i].length() < small ){ small = q[i].length(); j = i; } // put arriving customer in smallest queue Customer* c = new Customer(customerNo, arrTime, duration ); c->setStatus(j); // remember which queue the customer goes in q[j].enqueue(c); http://ecomputernotes.com
  • 28. Code for Simulation // check if this is the only customer in the. // queue. If so, the customer must be marked for // departure by placing him on the event queue. if( q[j].length() == 1 ) { c->setDepartureTime( arrTime+duration); Event* e = new Event(c, arrTime+duration ); pq.insert(e); } // get another customer from the input readNewCustomer(data); } http://ecomputernotes.com
  • 29. Code for Simulation int processDeparture( int qindex, int departTime, Event* event) { Customer* cinq = q[qindex].dequeue(); int waitTime = departTime - cinq->getArrivalTime(); totalTime = totalTime + waitTime; count = count + 1; // if there are any more customers on the queue, mark the // next customer at the head of the queue for departure // and place him on the eventList. if( q[qindex].length() > 0 ) { cinq = q[qindex].front(); int etime = departTime + cinq->getTransactionDuration(); Event* e = new Event( cinq, etime); pq.insert( e ); }} http://ecomputernotes.com
  • 30. Code for Simulation // print the final avaerage wait time. double avgWait = (totalTime*1.0)/count; cout << &quot;Total time: &quot; << totalTime << endl; cout << “Customer: &quot; << count << endl; cout << &quot;Average wait: &quot; << avgWait << endl; http://ecomputernotes.com
  • 31. You may be thinking that the complete picture of simulation is not visible. How will we run this simulation? Another important tool in the simulation is animation. You have seen the animation of traffic. Cars are moving and stopping on the signals. Signals are turning into red, green and yellow. You can easily understand from the animation. If the animation is combined with the simulation, it is easily understood. We have an animated tool here that shows the animation of the events. A programmer can see the animation of the bank simulation. With the help of this animation, you can better understand the simulation. http://ecomputernotes.com
  • 32. In this animation, you can see the Entrance of the customers, four tellers, priority queue and the Exit. The customers enter the queue and as the tellers are free. They go to the teller straight. Customer C1<30, 10> enters the bank. The customer C1 enters after 30 mins and he needs 10 mins for the transaction. He goes to the teller 1. Then customer C2 enters the bank and goes to teller 2. When the transaction ends, the customer leaves the bank. When tellers are not free, customer will wait in the queue. In the event priority queue, we have different events. The entries in the priority queue are like arr, 76 (arrival event at 76 min) or q1, 80 (event in q1 at 80 min) etc. Let’s see the statistics when a customer leaves the bank. At exit, you see the customer leaving the bank as C15<68, 3><77, 3>, it means that the customer C15 enters the bank at 68 mins and requires 3 mins for his transaction. He goes to the teller 4 but the teller is not free, so the customer has to wait in the queue. He leaves the bank at 77 mins.
  • 33. This course is not about the animation or simulation. We will solve the problems, using different data structures. Although with the help of simulation and animation, you can have a real sketch of the problem. http://ecomputernotes.com

Editor's Notes

  1. End of lecture 9
  2. End of lecture 9
  3. End of lecture 10